//获取http模块
var http = require("http");

var buf = require("buffer");

var data = buf.alloc(1000);

var json = require("json");

var url = require("url");

function http_accept(method, uri, res)
{
	print(method);
	print(uri);
	if(method == "get")
	{
		print(url.parse(uri, "name"));
		res.write("HTTP/1.1 200 OK\r\n");
		res.write("Content-Type: text/html\r\n");
		res.write("Content-Length: 78\r\n\r\n");
		res.write("<HTML>\r\n<BODY>\r\nSorry, the page you requested was not found.\r\n</BODY>\r\n</HTML>\r\n");
		res.end();
		http.close();
	}
}

function http_data(size)
{
	print(size);
	http.read(data, size);
	print(data.toString());
	var obj = json.parse(data.toString());
	var item = json.item(obj, "name");
	print(json.value(item));
	http.close();
}

http.on("connect", http_accept);
http.on("data", http_data);

function loop(){
	while(true){

	}
}

loop();

